<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>咨询测算查询</title>
		<%include("/common/include.html"){}%>
		<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
		<style type="text/css">
		.textbox {
			padding-right: 0px;
			background: url("${cxt !}/sb/themes/insdep/images/combo_arrow.png")
				no-repeat scroll right center transparent;
		}
		</style>
	</head>
	<body class="easyui-layout">
			<div data-options="region:'north',split: true,title:'快速查询'" style="height:200px;padding:10px;">
				<form id="customerInfoStatisticFrom" action="${cxt!}/customerInfoStatistic/excel">
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">首次进店-开始时间</label>
						<input name="_query.startTime" value='${startTime !}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">首次进店-结束时间</label>
						<input name="_query.endTime" value='${date(),dateFormat="yyyy-MM-dd"}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">代理商/门店</label>
						<input id="organ" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px;border-radius:3px" onclick="showMenu(); return false;" class="textbox" value="${curOrgan.name! }"/>
						<input name="_query.selOrganIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">市场负责人</label>
						<input id="organMangerIds" name="_query.organMangerIds" class="easyui-combobox theme-textbox-radius" style="width:212px;height:32px;text-align:center;" data-options="editable: false" >
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">门店小组</label>
						<input id="dempment" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px;text-align:center" onclick="showDempment(); return false;" class="textbox" value="-请选择-"/>
						<input name="_query.selDempmentIds" id="dempmentIds" type="hidden" value="-1">
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">顾客负责人</label>
						<input  id="customerManger" name="_query.customerManger" class=" easyui-combobox theme-textbox-radius" style="width:212px;height:32px;text-align:center" data-options="editable: false"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">顾客编号</label>
						<input  id="hybh" name="_query.hybh" class=" easyui-textbox theme-textbox-radius" style="width:212px;height:32px;text-align:center"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">顾客姓名</label>
						<input  name="_query.customerName" class=" easyui-textbox theme-textbox-radius" style="width:212px;height:32px;text-align:center"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">顾客手机号</label>
						<input  name="_query.customerPhone" class=" easyui-textbox theme-textbox-radius" style="width:212px;height:32px;text-align:center"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">顾客性别</label>
						<select name="_query.customerSex" class=" easyui-combobox theme-textbox-radius" style="width:212px;height:32px;text-align:center" data-options="editable: false">
							<option value="-1">请选择</option>
							<option value="女">女</option>
							<option value="男">男</option>
						</select>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">进店方式</label>
						<#code type="select" name="_query.jdfs" code="code_jdfs" isSelectDef="false" class="easyui-combobox inputBox theme-textbox-radius" style="width:212px;height:32px;text-align:center;" dataOptions="editable:false"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">疗程</label>
						<#treatment name="_query.lc" class="easyui-combobox inputBox theme-textbox-radius" style="width:212px;height:32px;text-align:center;" dataOptions="editable:false"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">疗程数</label>
						<select name="_query.treatment" class=" easyui-combobox theme-textbox-radius" style="width:212px;height:32px;text-align:center" data-options="editable: false">
							<option value="-1">请选择</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
							<option value="6">6</option>
						</select>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">未到店天数</label>
						<input name="_query.days" class=" easyui-textbox theme-textbox-radius" style="width:212px;height:32px;text-align:center"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">服务状态</label>
						<select name="_query.state" class=" easyui-combobox theme-textbox-radius" style="width:212px;height:32px;text-align:center" data-options="editable: false">
							<option value="-1">请选择</option>
							<!-- <option value="3">终止</option> -->
							<option value="1">服务中</option>
							<option value="6">终止</option>
						</select>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='searchFrom()' class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:212px">搜索</a>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='customerInfo_xls()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='deleteCus()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">删除</a>
					</div>
					
					</form>
	   	 	</div>
	   	 	<div data-options="region:'center',border: false" style="overflow-x:hidden;">
				<table id="customerInfoTable" style="width:100%;height:100%;">
				</table>
	    	</div>
	    	<div id="menuContent" class="menuContent" style="display: none; position: absolute;z-index: 10;">
				<ul id="organSelectTree" class="ztree" style="margin-top:0;width: 200px;"></ul>
			</div>
			<div id="dempContent" class="menuContent" style="display: none; position: absolute;z-index: 10;">
				<ul id="deptSelectTree" class="ztree" style="margin-top: 0;width: 200px;"></ul>
			</div>
			
		<script type="text/javascript">
			
			var $form = $('#customerInfoStatisticFrom');
			function searchFrom(){
				initCustomerInfoTable();
			}
			function customerInfo_xls(){
				$form.submit();
			}
			$(function() {
				var $form_div = $("#customerInfoStatisticFrom div");
				winResize($form_div);
				$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
					winResize($form_div);
				});
				initCustomerMangerData();//初始化顾客负责人为 -请选择-
			})
			function initTableTitle(){
				var name = $("#organ").val();
				var organMangerIds = $("#organMangerIds").val();
				var dempment = $("#dempment").val();
				var customerManger = $("#customerManger").val();
				
				if(organMangerIds != -1){
					name += "/" + $("#organMangerIds").combo('getText');
				}
				if(dempment != -1 && dempment != '-请选择-'){
					name += "/" + dempment;
				}
				if(customerManger != -1){
					name += "/" + $("#customerManger").combo('getText');
				}
				return name;
			}
			var columns = [[
							
						//	{field:'customerids',title:'ids',width:130,align:'center',hidden:true},
							{field:'firstweight',title:'首次进店<br />体重',width:50,align:'center',sortable:true},
					  		{field:'targetweight',title:'目标<br />体重',width:50,align:'center',sortable:true},
					  		{field:'delweight',title:'应减斤数',width:50,align:'center',sortable:true},
					  		{field:'nowweight',title:'当前体重',width:50,align:'center',sortable:true},
					  		{field:'registtime',title:'首次进店<br />日期',width:100,align:'center',sortable:true},
					  		{field:'tostoredate',title:'最近到店<br />日期',width:100,align:'center',sortable:true},
					  		{field:'lc',title:'疗程',width:90,align:'center'},
					  		{field:'sjtreatment',title:'疗程数',width:30,align:'center',sortable:true},
					  		{field:'sex',title:'性别',width:50,align:'center'},
					  		{field:'age',title:'年龄',width:50,align:'center',sortable:true},
					  		{field:'height',title:'身高(cm)',width:50,align:'center',sortable:true},
					  		//{field:'phone',title:'手机号',width:100,align:'center'},
					  		{field:'organname',title:'门店',width:130,align:'center'},
					  		//{field:'agentids',title:'agentids',width:130,align:'center',hidden:true},
					  		//{field:'agentname',title:'店长',width:130,align:'center'},
					  		{field:'organbh',title:'organbh',width:100,align:'center',hidden:true},
					  		{field:'deptids',title:'deptids',width:100,align:'center',hidden:true},
					  		{field:'minweight',title:'最低体重',width:100,align:'center',hidden:true},
					  		{field:'customertype',title:'customerType',width:100,align:'center',hidden:true},
					  		{field:'dept',title:'小组',width:100,align:'center',sortable:true},
					  		{field:'fzrids',title:'fzrids',width:100, align:'center',hidden:true},
					  		{field:'fzr',title:'顾客负责人',width:100,align:'center'},
					  		{field:'customerids',title:'customerids',width:100, align:'center',hidden:true},
					  		//{field:'username',title:'用户名',width:100,align:'center'},
					  		{field:'hybh',title:'会员编号',width:100,align:'center',sortable:true},
					  		
					  		//{field:'sfzmhm',title:'身份证号码',width:150,align:'center'},
					  		
					  		
					  		
					  		
					  		{field:'agreementids',title:'agreementids',width:100,align:'center',hidden:true},
					  		{field:'agreementbh',title:'协议编号',width:150,align:'center',sortable:true,
					  			formatter: function(value,row,index){
					  				var ids = row.customerids;
									return '<a href="#" style="color: blue;" class="button-edit" onclick="lookAgreementInfo(\'' + ids + '\')">' + value + '</a>';
								}
					  		},
					  		
					  		//{field:'intotype',title:'进店方式',width:100,align:'center'},
					  		/* {field:'jsr',title:'介绍人',width:100,align:'center',
					  			formatter: function(value,row,index){
									if (row.jsr){
										var ids = row.jsrids;
										return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
									} else {
										return "无";
									}
					  			}
					  		}, */
					  		//{field:'jsrids',title:'jsrids',width:100,align:'center',hidden:true},
					  		{field:'datastatus',title:'服务状态',width:100,align:'center',
					  			formatter: function(value,row,index){
									if (row.datastatus == 1){
										if(row.customertype == "2" && row.minweight<=row.targetweight){
											return "标体并巩固";
										}else if(row.customertype == "2" && row.minweight>row.targetweight){
											return "满意并巩固";
										}else{
											return "服务中";
										}
										
									} else if(row.datastatus == 3){
										return "终止";
									}else if(row.datastatus == 2){
										return "服务中";
									}else if(row.datastatus == 5){
										return "转店终止";
									}else if(row.datastatus == 6){
										return "退疗程款终止";
									}
								}
					  		},
					  		//{field:'areaids',title:'areaids',width:130,align:'center',hidden:true},
							//{field:'areaname',title:'市场经理',width:130,align:'center'},
							//{field:'dlids',title:'dlids',width:130,align:'center',hidden:true},
							//{field:'dlname',title:'代理商',width:130,align:'center'},
							//{field:'mangerids',title:'mangerids',width:130,align:'center',hidden:true},
							//{field:'mangername',title:'片区经理',width:130,align:'center'},
							{field:'organids',title:'organids',width:130,align:'center',hidden:true}
					      ]];
			function initCustomerInfoTable(){
				var name = initTableTitle();
				$('#customerInfoTable').datagrid({
					title:name,
					cls: "theme-datagrid",
					toolbar: '#tb',
					singleSelect: false,
					rownumbers: true, //显示序号
					pagination: true,
					pageSize: 10,
					url: "${cxt!}/customerInfoStatistic/view",
					queryParams: sy.serializeObject($form),
				    method: 'post',
					collapsible: true,
					remoteSort:false,
					multiSort:true,
					frozenColumns:[[
										{field:'check',checkbox:true},
										{field:'name',title:'姓名',width:80,align:'center',
											formatter: function(value,row,index){
												var ids = row.customerids;
											return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
										}
										
										}
					        	]],
					columns:columns,
					onLoadSuccess:function(){
						$('#customerInfoTable').datagrid("selectRow", 0);
						// 获取主表选中行
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
			//查看顾客协议
			function lookAgreementInfo(ids){
				loadViewDialog('查看顾客协议', '${cxt!}/bentryRegister/showAgree?customerIds=' + ids);
			}
			//查看顾客详细信息
			function lookCustomerInfo(ids){
				loadViewDialog('查看顾客详细信息', '${cxt!}/customerInfoStatistic/lookCustomerInfo?ids=' + ids);
			}
			//初始化负责人下拉框
			function initCustomerMangerSelect(ids,flag){
				var url = "/common/getUsersByOrgan";
				if(flag == 1){
					url = "/common/getUsersByDept"
				}
				var param = {
						'ids':ids
					};
				var data = common_ajax.ajaxFunc(url,param,"json");
				initCustomerMangerData(data);
				
			}
			
			function deleteCus(){
				var con;
				con=confirm("确认删除顾客?"); //在页面上弹出对话框
				if(con==true){
					var checkRows=$('#customerInfoTable').datagrid('getChecked');
					var ids = "";
					for(var i=0;i<checkRows.length;i++)
					{	
					if(i==checkRows.length-1){
						ids = ids+checkRows[i].customerids;
					}else{
						ids = ids+checkRows[i].customerids+",";	
					}
					}	
					if(ids!=""){
						var url="/bentryRegister/deleteCus";
						var data={"customerIds":ids};
						var reData = common_ajax.ajaxFunc(url, data);
	 					if(reData!="success")
						{		
	 						$.alert(parent.$,reData);
							 
						}else{
							 $.slideMsg("删除成功", parent.$);
							
						}
					}else
					{
						 $.alert(parent.$, "请先选择顾客！");
					}
					
				}
				
				
			}
			//初始化负责人下拉数据
			function initCustomerMangerData(data){
				var data = data;
				if(typeof(data) == "undefined"){
					data = [];
				}
				data.unshift({  
                    'ids': '-1',  
                    'name': '-请选择-'  
                });
				$('#customerManger').combobox({
				    data:data,
				    valueField:'ids',
				    textField:'name',
				    onLoadSuccess : function(){  
				    	 var val = $(this).combobox('getData');  
		                    for (var item in val[0]) {  
		                        if (item == 'ids') {  
		                            $(this).combobox('select', val[0][item]);  
		                        }  
		                    }
			        }
				});
			}
			//初始化市场负责人下拉框
			function initMangerSelect(ids){
				var url = "/common/getOrganManger";
				var param = {
						'ids':ids
					};
				var data = common_ajax.ajaxFunc(url,param,"json");
				data.unshift({  
                     'ids': '-1',  
                     'name': '-请选择-'  
                 });
				$('#organMangerIds').combobox({
				    data:data,
				    valueField:'ids',
				    textField:'name',
				    onLoadSuccess : function(){  
				    	 var val = $(this).combobox('getData');  
		                    for (var item in val[0]) {  
		                        if (item == 'ids') {  
		                            $(this).combobox('select', val[0][item]);  
		                        }  
		                    }
			        }
				});
			}
		</script>
		<script type="text/javascript">
			var setting = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick,
					onAsyncSuccess : organTreeOnAsyncSuccess
				}
			};
			var flag=0;//只初始化一次标识
			function organTreeOnAsyncSuccess(event, treeId, msg) {
				if(flag == 0){
					var organTree = $.fn.zTree.getZTreeObj("organSelectTree");
					var nodes = organTree.getNodes();
					initMangerSelect(nodes[0].id);
					if(nodes[0].isParent == false){
						initDeptTree(nodes[0].id);
					}else{
						initDeptTree(0);
					}
					initCustomerInfoTable();
					flag = 1;
				}
			}
			function onClick(e, treeId, treeNode) {
				initCustomerMangerData();
				initMangerSelect(treeNode.id);
				if(treeNode.isParent == false){
					initDeptTree(treeNode.id);
				}else{
					initDeptTree(0);
				}
				var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
						
					}
				}
				var cityObj = $("#organ");
				cityObj.attr("value", path);
				$("#organIds").attr("value", treeNode.id);
				hideMenu();
			}
			function showMenu() {
				var cityObj = $("#organ");
				var cityOffset = $("#organ").offset();
				$("#menuContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
		
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn"
						|| event.target.id == "menuContent" || $(event.target)
						.parents("#menuContent").length > 0)) {
					hideMenu();
				}
			}
			$.fn.zTree.init($("#organSelectTree"), setting);
		</script>
		<script type="text/javascript">
			function initDeptTree(organIds){
				if(organIds != 0){
					var deptSetting = {
							async : {
								enable : true,
								url : '${cxt!}/common/getDempTree',
								autoParam : [ "id=ids" ],//, "name=n", "level=lv"
								otherParam : {
									"organIds" : organIds
								},
								type : "post"
							},
							view : {
								dblClickExpand : false
							},
							data : {
								simpleData : {
									enable : true
								}
							},
							callback : {
								onClick : deptOnClick,
								onAsyncSuccess : deptTreeOnAsyncSuccess
							}
						};
					$.fn.zTree.init($("#deptSelectTree"), deptSetting);
				}else{
					var objtree = $.fn.zTree.getZTreeObj("deptSelectTree");
					if(objtree != null){
						objtree.destroy();
					}
					$("#dempment").val("-请选择-");
					$("#dempmentIds").val("-1");
				}
				
			}
			
			function deptTreeOnAsyncSuccess(event, treeId, msg) {
				initCustomerMangerSelect($("#organIds").val(), 0);
			}
			function deptOnClick(e, treeId, treeNode) {
				if(treeNode.bh == '01'){
					initCustomerMangerSelect($("#organIds").val(), 0);
					$("#dempment").val(treeNode.name);
					$("#dempmentIds").val('-1');
				}else{
					initCustomerMangerSelect(treeNode.id, 1);
					initDept_input(treeNode);
				}
				hideDept();
			}
			//初始化input
			function initDept_input(treeNode){
				$("#dempment").val(treeNode.name);
				$("#dempmentIds").val(treeNode.id);
			}
			function showDempment() {
				var cityObj = $("#dempment");
				var cityOffset = $("#dempment").offset();
				$("#dempContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
		
				$("body").bind("mousedown", deptOnBodyDown);
			}
			function hideDept() {
				$("#dempContent").fadeOut("fast");
				$("body").unbind("mousedown", deptOnBodyDown);
			}
			function deptOnBodyDown(event) {
				if (!(event.target.id == "menuBtn"
						|| event.target.id == "dempContent" || $(event.target)
						.parents("#dempContent").length > 0)) {
					hideDept();
				}
			}
		</script>
	</body>
</html>
